package com.dao;

import com.domain.Student;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface StuDao {
    /**
     * 查询全部
     * @return
     */
    @Select("SELECT * FROM student")
    List<Student> findAll();

    /**
     * 添加功能
     * @param stu
     * @return
     */
    @Insert("INSERT INTO student VALUES (null,#{name},#{age},#{sex},#{address})")
    Integer addStu(Student stu);

    /**
     * 删除功能
     * @param id
     * @return
     */
    @Delete("delete from student where id = #{id}")
    Integer delStu(Integer id);

    /**
     * 修改功能
     * @param stu
     * @return
     */
    @Update("update student set name=#{name},age=#{age},sex=#{sex},address=#{address} where id = #{id}")
    Integer updateStu(Student stu);

    /***
     * 条件查询
     * @param stu
     * @return
     */
    @Select(value = {" <script>" +
            " SELECT * FROM student " +
            " <where> 1=1 " +
            " <if test=\"name != null\"> AND name=#{name}</if> " +
            " <if test=\"sex != null\" >  AND sex=#{sex}</if> " +
            " </where>" +
            " </script>"})
    List<Student> findStu(Student stu);
}
